﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace ChessGameV2.Scenes
{
    public class StartScene
    {
        SpriteBatch sp;
        Texture2D background;
        bool isSound=false;

        #region but properties
        Texture2D butNewGameR;
        Texture2D butNewGameB;
        Vector2 posNewGame;
        bool NGisMouseOver=false;

        Texture2D butLoadGameR;
        Texture2D butLoadGameB;
        Vector2 posLoadGame;
        bool LGisMouseOver=false;

        Texture2D butSettingR;
        Texture2D butSettingB;
        Vector2 posSetting;
        bool SisMouseOver=false;

        Texture2D butQuitR;
        Texture2D butQuitB;
        Vector2 posQuit;
        bool QisMouseOver=false;

        #endregion

        public StartScene(SpriteBatch _sp)
        {
            this.sp = _sp;
            posNewGame = new Vector2(300, 200);
            posLoadGame = new Vector2(300, 270);
            posSetting = new Vector2(300, 340);
            posQuit = new Vector2(340, 410);
        }
        public void LoadContent(ContentManager Content)
        {
            background = Content.Load<Texture2D>("StartScene/background");

            butNewGameR = Content.Load<Texture2D>("StartScene/button/NewGameRed");
            butNewGameB = Content.Load<Texture2D>("StartScene/button/NewGameBlue");
            butLoadGameR = Content.Load<Texture2D>("StartScene/button/LoadGameRed");
            butLoadGameB = Content.Load<Texture2D>("StartScene/button/LoadGameBlue");
            butSettingR = Content.Load<Texture2D>("StartScene/button/SettingRed");
            butSettingB = Content.Load<Texture2D>("StartScene/button/SettingBlue");
            butQuitR = Content.Load<Texture2D>("StartScene/button/butQuitRed");
            butQuitB = Content.Load<Texture2D>("StartScene/button/butQuitBlue");
        }
        public void Update()
        {
            if (Game1.currentMouseState.X > posNewGame.X + 11 && Game1.currentMouseState.Y > posNewGame.Y + 11 && Game1.currentMouseState.Y < posNewGame.Y + 56)
            {
                if(isSound) Sounds.Move();
                isSound = false;
                this.NGisMouseOver = true;
                if (Game1.lastMouseState.LeftButton == ButtonState.Released && Game1.currentMouseState.LeftButton == ButtonState.Pressed)
                {
                    Game1.gameScene = GameScene.Playing;
                }
            }
            else if (Game1.currentMouseState.X > posLoadGame.X + 11 && Game1.currentMouseState.Y > posLoadGame.Y + 11 && Game1.currentMouseState.Y < posLoadGame.Y + 56)
            {
                if (isSound) Sounds.Move();
                isSound = false;
                this.LGisMouseOver = true;
                if (Game1.lastMouseState.LeftButton == ButtonState.Released && Game1.currentMouseState.LeftButton == ButtonState.Pressed)
                {
                    Game1.gameScene = GameScene.LoadGame;
                }
            }
            else if (Game1.currentMouseState.X > posSetting.X + 11 && Game1.currentMouseState.Y > posSetting.Y + 11 && Game1.currentMouseState.Y < posSetting.Y + 56)
            {
                if (isSound) Sounds.Move();
                isSound = false;
                this.SisMouseOver = true;
                if (Game1.lastMouseState.LeftButton == ButtonState.Released && Game1.currentMouseState.LeftButton == ButtonState.Pressed)
                {
                    Game1.gameScene = GameScene.Setting;
                }
            }
            else if (Game1.currentMouseState.X > posQuit.X + 11 && Game1.currentMouseState.Y > posQuit.Y + 11 && Game1.currentMouseState.Y < posQuit.Y + 56)
            {
                if (isSound) Sounds.Move();
                isSound = false;
                this.QisMouseOver = true;
                if (Game1.lastMouseState.LeftButton == ButtonState.Released && Game1.currentMouseState.LeftButton == ButtonState.Pressed)
                {
                    Game1.gameScene = GameScene.Quit;
                }
            }
            else
            {
                isSound = true;
                this.NGisMouseOver = false;
                this.LGisMouseOver = false;
                this.SisMouseOver = false;
                this.QisMouseOver = false;
            }
        }        
        public void Draw()
        {
            sp.Draw(background, Vector2.Zero, Color.White);
            if (NGisMouseOver) sp.Draw(butNewGameR, posNewGame, Color.White);
            else sp.Draw(butNewGameB, posNewGame, Color.White);
            if (LGisMouseOver) sp.Draw(butLoadGameR, posLoadGame, Color.White);
            else sp.Draw(butLoadGameB, posLoadGame, Color.White);
            if (SisMouseOver) sp.Draw(butSettingR, posSetting, Color.White);
            else sp.Draw(butSettingB, posSetting, Color.White);
            if (QisMouseOver) sp.Draw(butQuitR, posQuit, Color.White);
            else sp.Draw(butQuitB, posQuit, Color.White);
        }
    }
}
